﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Backend
{


    
    [KnownType(typeof(Leg))]
    [DataContract]
    public class Flight
    {
        [DataMember]
       private List<Leg> legs;
        [DataMember]
       private double totalPrice;

  

 

        public Flight()
        {
            legs = new List<Leg>();
            totalPrice = 0;
        }

        public void AddLeg(Leg leg)
        {
            legs.Add(leg);
            
           //Update the total price
           CalculateTotalPrice();


        }

        private void CalculateTotalPrice()
        {
            totalPrice = 0;
            foreach (Leg leg in legs)
            {

                totalPrice += leg.Price;
            }
        }

        public List<Leg> Legs
        {
            get { return legs; }
            set { legs = value; }
        }

  

        public double TotalPrice
        {
            get {
                return totalPrice; }
            set { totalPrice = value; }
        }
        
 


    }
}
